#!/usr/bin/env bash

set -e
set -v

OS=$1
shift

VERSION=$1
shift

ROOT=$(pwd)
PACK=${ROOT}/package/${OS}

mkdir -p ${PACK}
pushd ${PACK}
  mkdir -p vimspector/opt/vimspector
  pushd vimspector/opt/vimspector
    for d in autoload plugin python3 vendor doc support; do
      if [[ -d ${ROOT}/$d ]]; then
        cp -r ${ROOT}/$d .
      fi
    done
    mkdir -p gadgets
    cp -r ${ROOT}/gadgets/${OS} gadgets/
    for f in install_gadget.py \
             CODE_OF_CONDUCT.md \
             CONTRIBUTING.md \
             LICENCE \
             README.md; do
      cp ${ROOT}/${f} .
    done
  popd
popd

cd ${ROOT}/package
tar zcvf ${OS}-${VERSION}.tar.gz -C ${OS} vimspector
